<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="运输公司" prop="companyName">
        <el-input v-model="queryParams.companyName" placeholder="请输入运输公司名称" clearable style="width: 240px" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="用户状态" clearable style="width: 240px">
          <el-option label="启用" :value="0" />
          <el-option label="禁用" :value="-1" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['biz:residentCompany:add']">新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="info" plain icon="el-icon-upload2" size="mini">导入</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="warning" plain icon="el-icon-download" size="mini">导出</el-button>
        </el-col>
      </el-row>

    </el-form>

    <el-table :data="tableData" style="width: 100%">
      <el-table-column type="index" label="序号" width="50" align="center" />
      <el-table-column label="企业编码" align="center" key="companyCode" width="150" :show-overflow-tooltip="true" prop="companyCode" />
      <el-table-column label="运输公司" prop="companyName"></el-table-column>
      <el-table-column label="联系人" prop="contacts"></el-table-column>
      <el-table-column label="联系电话" prop="mobile"></el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          {{ scope.row.status === 0 ? "启用" : "禁用" }}
        </template>
      </el-table-column>

      <el-table-column label="操作" fixed="right" align="center" width="160" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleUpdate(scope.row)" v-hasPermi="['biz:residentCompany:edit']">修改</el-button>
          <el-button size="mini" type="text" @click="handleDetail(scope.row)" v-hasPermi="['biz:residentCompany:query']">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <AddOrEdit :open="open" :title="title" @cancel="cancel" @submit-form="submitForm"></AddOrEdit>

  </div>
</template>

<script>
import { listCompany } from '@/api/organization/transportCompany.js'
import { AddOrEdit } from './component/index.js'
export default {
  name: 'TransportCompany',
  components: {
    AddOrEdit 
  },
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyName: undefined,
        status: ''
      },
      // 总条数
      total: 0,
      tableData: [] // 添加表格数据
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      // 处理查询逻辑
      listCompany(this.queryParams)
        .then((res) => {
          console.log(res)
          this.tableData = res.rows // 将获取的数据赋值给表格数据
          this.total = res.total // 更新总条数
        })
        .catch((err) => {
          console.error(err)
        })
    },

    // 搜索按钮操
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },

    resetQuery() {
      // 重置查询条件
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        companyName: undefined,
        status: ''
      }
      this.getList() // 重置后重新获取数据
    },

    //新增按钮操作
    handleAdd() {
      this.open = true
      this.title = '添加运输公司'
    },
    // 新增弹框取消按钮
    cancel() {
      this.open = false
    },
    //提交按钮
    submitForm: function () {
      this.open = false
      this.getList()
    },
    //分页
    handlePagination(pageNum, pageSize) {
      this.queryParams.pageNum = pageNum
      this.queryParams.pageSize = pageSize
      this.getList()
    }
  }
}
</script>
